package bobaini.com.dead_exchange;

import bobaini.com.util.RabbitMqUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

/**
 * ClassName: Consumer01
 * author: bob.ly
 * Version: 1.0.0
 * DateTime: 2021/07/25-22:44:00
 * Description:假设当前是正常队列, 只是将消息存放到死信队列中.
 */
public class Consumer02 {
    private static final String DEAD_EXCHANGE = "dead_exchange";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();

        /**
         * 声明死信交换机
         */
        channel.exchangeDeclare(DEAD_EXCHANGE, BuiltinExchangeType.DIRECT);
        /**
         * 声明死信队列
         */
        channel.queueDeclare("dead-queue", false, false, false, null);
        channel.queueBind("dead-queue", DEAD_EXCHANGE, "lisi");

        DeliverCallback deliverCallback = (tag, message) -> {
            System.out.println("消费者消费死信队列中的消息:" + new String(message.getBody(), "UTF-8"));
        };
        channel.basicConsume("dead-queue", true, deliverCallback, c -> {
        });
    }
}
